<template>
  <div>
    <form>
      <p>姓名：<input type="text" v-model="uname" /></p>
      <p>年龄：<input type="number" v-model="age" /></p>
      <p>
        身高：<input type="number" v-model.number="shenggao" /><span>(米)</span>
      </p>
      <p>
        体重：<input type="number" v-model.number="tizhong" /><span>(kg)</span>
      </p>
      <p>病史：<input type="text" v-model="bingshi" /></p>
      <button @click.prevent="add">诊断</button>
    </form>
    <div v-if="flag">患者：{{ uname }} ,你的诊断结果是：{{ result }}</div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      flag: false,
      uname: '',
      age: 0,
      shenggao: 0,
      tizhong: 0,
      bingshi: '',
      result: ''
    }
  },
  methods: {
    add () {
      this.flag = true
      let BMI = this.tizhong / (this.shenggao * this.shenggao)
      if (BMI < 18.5) {
        this.result = `体重过轻`
      } else if (BMI < 24.9 && BMI > 18.5) {
        this.result = '体重正常'
      } else {
        this.result = '体重过重'
      }
    }
  }
}
</script>

<style></style>
